#ifndef MACROSMANAGER_H
#define MACROSMANAGER_H

#include "manager.h"
#include <wx/regex.h>
#include <wx/filename.h>

class wxMenuBar;
class M_Code_Project;
class ProjectBuildTarget;
class EditorBase;
class UserVariableManager;

WX_DECLARE_STRING_HASH_MAP( wxString, MacrosMap );

class MacrosManager : public Mgr<MacrosManager> {
  public:
    friend class Manager;
    friend class Mgr<MacrosManager>;
    void CreateMenu( wxMenuBar* menuBar );
    void ReleaseMenu( wxMenuBar* menuBar );
    void ReplaceMacros( wxString& buffer, ProjectBuildTarget* target = nullptr, bool subrequest = false );
    wxString ReplaceMacros( const wxString& buffer, ProjectBuildTarget* target = nullptr );
    void ReplaceEnvVars( wxString& buffer ) { ReplaceMacros( buffer ); }  ;
    void RecalcVars( M_Code_Project* project, EditorBase* editor, ProjectBuildTarget* target );
    void ClearProjectKeys();
    void Reset();
  protected:
    ProjectBuildTarget* m_LastTarget;
    M_Code_Project* m_LastProject;
    wxFileName m_ProjectWxFileName;
    wxFileName m_WorkspaceWxFileName;
    wxString m_AppPath;
    wxString m_DataPath;
    wxString m_Plugins;
    wxString m_ActiveEditorFilename;
    int m_ActiveEditorLine;
    int m_ActiveEditorColumn;
    wxString m_WorkspaceFilename;
    wxString m_WorkspaceName;
    wxString m_WorkspaceDir;
    wxString m_ProjectFilename;
    wxString m_ProjectName;
    wxString m_ProjectDir;
    wxString m_ProjectTopDir;
    wxString m_ProjectFiles;
    wxString m_Makefile;
    wxString m_TargetOutputDir;
    wxString m_TargetName;
    wxString m_TargetOutputBaseName;
    wxString m_TargetOutputFilename;
    wxString m_TargetFilename;
    MacrosMap m_Macros;
    wxRegEx m_RE_Unix;
    wxRegEx m_RE_DOS;
    wxRegEx m_RE_If;
    wxRegEx m_RE_IfSp;
    wxRegEx m_RE_Script;
    wxRegEx m_RE_ToAbsolutePath;
    wxRegEx m_RE_To83Path;
    wxRegEx m_RE_RemoveQuotes;
    UserVariableManager *m_UserVarMan;
  private:
    MacrosManager();
    ~MacrosManager();
    wxString EvalCondition( const wxString& cond, const wxString& true_clause, const wxString& false_clause, ProjectBuildTarget* target );
    int MatchBrace( const wxString& buffer, int index );
};

#endif

